DAY15:Descending Order


Posted by birdbirdmurmur on 2023-07-28

題目連結:

Descending Order

解法:

function descendingOrder(n){
  const str = n.toString().split('').map(Number);
   return Number(str.sort((a, b) => b - a).join(''));
}

筆記:

使用split('')方法將該字符串拆分成一個字符數組
使用map(Number)方法將每個字符轉換回數字
接下來使用sort((a, b) => b - a)方法對數字數組進行降序排序
最後用join加入回傳

解了一堆7、8kyu,現在已經升級到6kyu了
要挑戰rank up的題目開始出現4kyu(怕
~接下來就是瘋狂看solutions了吧~


#javascript #Codewars #split #sort #join







Related Posts

Unlocking the Secrets: How to Farm Diablo 4 Gold and Rare Items Like a Pro

Unlocking the Secrets: How to Farm Diablo 4 Gold and Rare Items Like a Pro

PHP & CGI 相關知識

PHP & CGI 相關知識

[Note] React - Hooks: useRef

[Note] React - Hooks: useRef


Comments